package com.joy.tap.sdk;

import com.joy.tap.sdk.ad.TapVideoCallback;
import com.joy.tap.sdk.bridge.TapCocosBridge;
import com.joy.tap.sdk.ad.TapVideoManger;

import org.json.JSONObject;

public class TapAdSdk {

    public static void showAd(String ad_source) {
        showAd(ad_source, 3);
    }

    private static void adCallBack(String state, String ad_source) {
        try {
            JSONObject jsonObject = new JSONObject();
            jsonObject.put("ad_source", ad_source);
            TapCocosBridge.getInstance().XSSdkCallback(state, jsonObject.toString());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private static void showAd(String ad_source, int q) {
        showAd(new TapVideoCallback() {
            @Override
            public void onAdOver() {
                adCallBack("ad_over_joy", ad_source);
            }

            @Override
            public void onAdError() {
                adCallBack("ad_error_joy", ad_source);
            }
        }, q);
    }

    public static void showAd(TapVideoCallback callback, int i) {
        try {
            TapVideoManger.getReward1Instance().showVideo(TapCocosBridge.mainGameActivity.get(),callback);
        } catch (Exception e) {
            e.printStackTrace();
            callbackAdError(callback);
        }
    }


    private static void callbackAdError(TapVideoCallback callback) {
        if (callback != null) {
            callback.onAdError();
        }
    }


}
